package day10;

/**
 *  “111001110001011210101110110010021001111011000002100111000101010210010000000101112110101111010100211111111000011002110011101100101211000100101001121100010000100012101010001000000”
 *
 * 这是一句话，包含着重要的商业机密，但它已经被加密过了，请解密它
 * Created by Shinelon on 2016/9/29.
 */
public class HomeWork {

    public static void main(String[] args) {
        String string1="111001110001011210101110110010021001111011000002100111000101010210010000000101112110101111010100211111111000011002110011101100101211000100101001121100010000100012101010001000000";
        String result = "";
        for (String s : string1.split("2")) {
            result += (char) Integer.parseInt(s,2);
        }

        System.out.println(result);

        System.out.println(encoding(result));
        System.out.println(encoding(result).equals(string1));
    }

    public static final String encoding(String source) {
        char[] chars = source.toCharArray();
        String result = "";
        for (char aChar : chars) {
            result += Integer.toString(((int) aChar), 2) + 2;
        }
        return result.substring(0, result.length() - 1);
    }
}
